<template>
    <div class="bod">
        <van-cell-group>
            <van-cell title="请假人" :value="info.name" />
            <van-cell title="请假课程" :value="info.kcname" />
            <van-cell title="请假时间" :value="info.sktime" />
        </van-cell-group>
        <div class="sae-textarea">
            <van-cell-group>
                <van-field type="textarea" rows="5" autosize v-model="info.reason" label="请假原因" />
            </van-cell-group>
        </div>
        <div class="btns">
            <van-button plain hairline type="info" @click="leaveApprove(2)">不允许</van-button>
            <van-button type="info" @click="leaveApprove(1)">允许</van-button>
        </div>
    </div>
</template>

<script>
import api from '@/api'
import { Toast } from 'vant'
export default {
  name: 'student-edit',
  data () {
    return {
      info: {}
    }
  },
  mounted () {
    this.leaveDetails()
  },
  methods: {
    // 请假详情  agencyStudentLeaveDetails
    leaveDetails () {
      let params = {
        id: JSON.parse(this.$route.query.data).id
      }
      api.agencyStudentLeaveDetails({
        params,
        callback: res => {
          console.log(res)
          this.info = res.data.data
          if (this.info.sktime) {
            let date = new Date(parseInt(this.info.sktime) * 1000)
            let Y = date.getFullYear() + '-'
            let M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) + '-' : date.getMonth() +
                                1 + '-'
            let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' '
            let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() +
                                ':'
            let m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() +
                                ':'
            let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
            this.info.sktime = Y + M + D + h + m + s
          }
        }
      })
    },
    // 请假审批  agencyStudentLeaveApprove
    leaveApprove (status) {
      let params = {
        id: JSON.parse(this.$route.query.data).id,
        status: status
      }
      api.agencyStudentLeaveApprove({
        params,
        callback: res => {
          console.log(res)
          if (res.data.error_code === 0) {
            Toast.success(res.data.message)
          } else {
            Toast.fail(res.data.message)
          }
        }
      })
    }

  }
}
</script>

<style scoped>
    .bod {
        height: 100%;
        background-color: #F2F2F2;
    }

    .van-cell-group {
        margin-top: 10px;
    }
</style>
